package com.softeem.score.manager.controller.admin;

import com.github.pagehelper.PageInfo;
import com.softeem.score.common.log.annotation.Log;
import com.softeem.score.common.log.enums.OperatorType;
import com.softeem.score.manager.service.TeacherService;
import com.softeem.score.model.dto.TeacherDto;
import com.softeem.score.model.entity.school.Teacher;
import com.softeem.score.model.vo.common.Result;
import com.softeem.score.model.vo.common.ResultCodeEnum;
import com.softeem.score.model.vo.school.MapVo;
import com.softeem.score.model.vo.school.TeacherVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhu
 * @since 2024-02-14
 */
@Tag(name = "教师管理")
@RestController
@RequestMapping("/admin/school/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @Operation(summary = "分页查询教师列表")
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<TeacherVo>> findByPage(TeacherDto teacherDto,
                                                  @PathVariable(value = "pageNum") Integer pageNum,
                                                  @PathVariable(value = "pageSize") Integer pageSize) {
        PageInfo<TeacherVo> pageInfo = teacherService.findByPage(teacherDto, pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询所有的教师")
    @GetMapping("/findAllTeacher")
    public Result<List<MapVo>> findAllTeacher() {
        List<MapVo> allTeacher = teacherService.findAllTeacher();
        return Result.build(allTeacher, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "通过课程查询教师", businessType = 0, operatorType = OperatorType.MANAGE)
    @Operation(summary = "通过课程查询教师")
    @GetMapping(value = "/findTeacherByCourseId/{courseId}")
    public Result<List<MapVo>> findTeacherByCourseId(@PathVariable(value = "courseId") Long courseId) {
        List<MapVo> teacherlist = teacherService.findTeacherByCourseId(courseId);
        return Result.build(teacherlist, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "查询当前学院的所有老师", businessType = 0, operatorType = OperatorType.MANAGE)
    @Operation(summary = "查询当前学院的所有老师")
    @GetMapping(value = "/getAllTeacherByCollegeId/{collegeId}")
    public Result getAllTeacherByCollegeId(@PathVariable(value = "collegeId") Long collegeId) {
        List<MapVo> mapVoList = teacherService.getAllTeacherByCollegeId(collegeId);
        return Result.build(mapVoList, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "新增教师", businessType = 1, operatorType = OperatorType.MANAGE)
    @Operation(summary = "新增教师")
    @PostMapping(value = "/saveTeacher")
    public Result saveTeacher(@RequestBody Teacher teacher) {
        teacherService.saveTeacher(teacher);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "更新教师信息", businessType = 2, operatorType = OperatorType.MANAGE)
    @Operation(summary = "更新教师信息")
    @PutMapping(value = "/updateTeacher")
    public Result updateSysUser(@RequestBody Teacher teacher) {
        teacherService.updateSysUser(teacher);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "删除教师", businessType = 3, operatorType = OperatorType.MANAGE)
    @Operation(summary = "删除教师")
    @DeleteMapping(value = "/deleteTeacherByTeacherNumber/{teacherNumber}")
    public Result deleteTeacherByTeacherNumber(@PathVariable(value = "teacherNumber") String teacherNumber) {
        teacherService.deleteTeacherByTeacherNumber(teacherNumber);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}

